const osssdk = require('./xstore/oss');
const upload = require('./xstore/upload');

// const BUCKET = 'yqy-oss';
// const PART_SIZE = 1000 * 1024 * 1024; // 1g以下直传
// const ACCESS_KEY_ID = 'LTAI5tPs5Gt44yFMfafZDgff';
// const SECRECT_ACCESS_KEY = 'Byeget6lTHoxHe9OJ6VkF78F1Qov71';
// const END_POINT = 'https://yqy-oss.oss-cn-hangzhou.aliyuncs.com';
// const REGION = 'oss-cn-hangzhou'

// const config = {
// 	region: REGION,
// 	bucket: BUCKET,
// 	accessKeyId: ACCESS_KEY_ID,
// 	accessKeySecret: SECRECT_ACCESS_KEY,
// 	endpoint: END_POINT
// };

const BUCKET = 'fsi.zgfznews.com/xyyqx_static';
const PART_SIZE = 1000 * 1024 * 1024; // 1g以下直传
const ACCESS_KEY_ID = '3GXMSP5ZAXFXSZ98C2CP';
const SECRECT_ACCESS_KEY = 'nhVMJh51ORjBfTCgPWXsOkNyDsZPUY4BVrvOLex7';
const END_POINT = 'https://eos-hunan-1.cmecloud.cn';

const config = {
  Creds: {
    AccessKeyId: ACCESS_KEY_ID,
    SecretAccessKey: SECRECT_ACCESS_KEY
  },
  EndPoint: END_POINT
};

const ossClient = new osssdk.OSS(config)
const manager = new upload.UploadManager(ossClient);

export function uploadImgOrVideo(filePath, Acl = 'public-read') {
  if (!filePath) return;
  const now = new Date().getTime()
  const req = {
    Bucket: BUCKET,
    Key: now,
    FilePath: filePath,
    Acl,
    PartSize: PART_SIZE,
  };
  return new Promise((resolve, reject) => {
    manager.UploadFile(req, (err, res) => {
      if (err) return reject(err)
      resolve(res)
    })
  })
}
